package com.tourism.product.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tourism.product.domain.ProductType;
import com.tourism.product.service.IProductTypeService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品类型Controller
 * 
 * @author silenceEcho
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/type")
public class ProductTypeController extends BaseController
{
    @Autowired
    private IProductTypeService productTypeService;

    /**
     * 查询产品类型列表
     */
    @RequiresPermissions("tourism:type:list")
    @GetMapping("/list")
    public AjaxResult list(ProductType productType)
    {
        List<ProductType> list = productTypeService.selectProductTypeList(productType);
        return success(list);
    }

    /**
     * 导出产品类型列表
     */
    @RequiresPermissions("tourism:type:export")
    @Log(title = "产品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductType productType)
    {
        List<ProductType> list = productTypeService.selectProductTypeList(productType);
        ExcelUtil<ProductType> util = new ExcelUtil<ProductType>(ProductType.class);
        util.exportExcel(response, list, "产品类型数据");
    }

    /**
     * 获取产品类型详细信息
     */
    @RequiresPermissions("tourism:type:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(productTypeService.selectProductTypeByTypeId(typeId));
    }

    /**
     * 新增产品类型
     */
    @RequiresPermissions("tourism:type:add")
    @Log(title = "产品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductType productType)
    {
        return toAjax(productTypeService.insertProductType(productType));
    }

    /**
     * 修改产品类型
     */
    @RequiresPermissions("tourism:type:edit")
    @Log(title = "产品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductType productType)
    {
        return toAjax(productTypeService.updateProductType(productType));
    }

    /**
     * 删除产品类型
     */
    @RequiresPermissions("tourism:type:remove")
    @Log(title = "产品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(productTypeService.deleteProductTypeByTypeIds(typeIds));
    }
}
